package com.ositano.flutter_3des;

import androidx.annotation.NonNull;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
//import io.flutter.plugin.common.PluginRegistry.Registrar
import java.util.*;

public class Flutter3desPlugin implements FlutterPlugin, MethodCallHandler{

    @Override
    public void onAttachedToEngine(FlutterPluginBinding binding) {
        if (null == mContext) {
            mContext = binding.getApplicationContext();

            final MethodChannel channel = new MethodChannel(binding.getBinaryMessenger(), "flutter_3des");
            channel.setMethodCallHandler(this);
        }
    }

    @Override
    public void onDetachedFromEngine(FlutterPluginBinding binding) {

    }
    @Override
    public void onMethodCall(MethodCall call, Result result) {
        String callMethod = call.method;
        List<String> arguments = call.arguments as ArrayList<String>;
        String key = arguments[1];
        String iv = arguments[2];
        switch (call.method) {
            case "encrypt":
                result.success(Flutter3desPluginJava.encrypt(arguments[0], key, iv));
                break;
            case "encryptToHex":
                result.success(Flutter3desPluginJava.encryptToHex(arguments[0], key, iv));
                break;
            case "decrypt":
                result.success(Flutter3desPluginJava.decrypt(arguments[0], key, iv));
                break;
            case "decryptFromHex":
                result.success(Flutter3desPluginJava.decryptFromHex(arguments[0], key, iv));
                break;
        }
    }
}